home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / appkit.699 < prev    next >
Text File  |  1992-02-06  |  6KB  |  72 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f3\fmodern Courier;\f1\fswiss Helvetica;}
  2. \paperw11760
  3. \paperh7200
  4. \margl120
  5. \margr120
  6. {\colortbl\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ul0\fs28 multiple nib connections\
  8. \
  9. Q:  How can I make connections in Interface Builder between objects in different nib files
  10. \fc0 , or in the same one loaded multiple times?  \
  11. \
  12. A:  You can't
  13. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 . You need to make the association in your code. The object that is 
  14. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 the
  15. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0  nib file's owner should
  16. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0  take care of
  17. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0  communicat
  18. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 ing
  19. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0  with any other objects
  20. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0  (including the owners of other nib files)
  21. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 .  
  22. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 For example, t
  23. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 h
  24. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 e file's owner can have methods 
  25. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 t
  26. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 hat
  27. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0  return instance variables
  28. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0  r
  29. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 efer
  30. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 ring
  31. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0  to any objects 
  32. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 from
  33. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0  the nib file that you want other objects to be able to talk to. 
  34. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0  (You must have created outlets in Interface Builder for these objects, in order for the objects to be assigned to instance variables.) 
  35. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 The file's owner can also 
  36. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 set the delegate of an object it owns to be some
  37. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0  external object.\
  38. \
  39. It's conceptually impossible to make the connections in Interface Builder, because there's no way to know which 
  40. \i instance
  41. \i0  of an object from one nib file will be connected to an instance of some object from another nib file. Each nib file will be loaded at a different time during the program execution, and any nib file can get loaded multiple times.  Only your code "knows" when the various objects will get created—namely, when you call 
  42. \b loadNibSection:owner:
  43. \b0 .  Remember that nib files are just templates; the objects are unarchived when you load the nib file.  When you make connections in Interface Builder, you're really just making the template of these connections.  Only when the nib file is loaded do the objects and their interconnections get instantiated, so to speak.  If the other nib file hasn't been loaded yet, you can't connect to its objects, since they don't exist in your program yet. That's why connections are limited to nib files.  It's also one reason every nib file must have an owner: so that objects from that nib file can communicate with other objects in your program.\
  44. \
  45. The same logic applies to loading the same nib file multiple times. A typical use of loading the same nib file multiple times is in applications that have the notion of a document.  The document is described by a nib file that gets loaded each time you want a new document (usually when the user clicks on the "New" menu). There should generally be a new instance of the owner of the nib file for each time you want to load the same nib file. The only way to communicate between the objects in different documents is through their owners.\
  46. \
  47. One example of multiply loaded nib files is /NextDeveloper/Examples/SoundEditor.  In this app, SoundController is the main object that loads in the application's main nib file. It also is responsible for creating SoundDocuments, each of which loads in its own nib data. In other words, a new instance of the SoundDocument class is the file's owner for each "instance" of  SoundDocument.nib—or more precisely, for the objects collectively unarchived each time \
  48.     
  49. \f3\fs24 [NXApp loadNibSection:SoundDocument.nib owner:self];
  50. \f0\fs28 \
  51. is called in SoundDocument's 
  52. \b init
  53. \b0  method. Although it wasn't necessary, there could have been methods in SoundDocument to return the objects "inside" each SoundDocument's nib file.  For example, SoundDocument could have implemented a method  called 
  54. \b -soundView
  55. \b0  that returned the variable 
  56. \b mySoundView
  57. \b0 , which is an IB outlet. This way any other objects could have talked to the SoundView, by messaging SoundController to get the current document (with the 
  58. \b document
  59. \b0  method), and then messaging the current document to get its SoundView (with the 
  60. \b soundView
  61. \b0  method).\
  62.  
  63. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600 \
  64. See NextAnswer ib.510 for more on the concept of a file's owner.\
  65. \
  66. QA699\
  67. \
  68. Valid for 1.0\
  69. Valid for 2.0\
  70. \
  71.  
  72.